<template>
	<view class="content">
		<view class="info-block">
			<view class="title FangZhengHanZhenGuangBiaoJianTi">代表信息</view>
			<view class="info-item">
				<image :src="info.photo" class="info-img"></image>
				<view class="name-item">
					<view class="name">{{info.name}}</view>
					<view class="type">性别：{{info.gender}}</view>
					<view class="type">政治面貌：{{info.political}}</view>
					<view class="type">类型：{{info.category_text}}</view>
					<view class="type">职务：{{info.position}}</view>
				</view>
			</view>
		</view>
		<view class="info-block">
			<view class="title FangZhengHanZhenGuangBiaoJianTi">反映人信息</view>
			<view class="form-block">
				<view class="title-item">
					<view class="must">*</view>
					<view class="name">反映人姓名</view>
				</view>
				<view class="form-item">
					<input :disabled="!submit" placeholder="请填写反映人姓名" v-model="detail.name" type="text" class="form-crl" maxlength="10" />
				</view>
			</view>
			<view class="form-block">
				<view class="title-item">
					<view class="must">*</view>
					<view class="name">反映人电话</view>
				</view>
				<view class="form-item">
					<input placeholder="请填写反映人电话" v-model="detail.mobile" type="text" class="form-crl" maxlength="11"
						placeholder-class="form-crl" disabled />
				</view>
			</view>
			<view class="form-block">
				<view class="title-item">
					<view class="must">*</view>
					<view class="name">问题描述</view>
				</view>
				<view class="form-item">
					<textarea :disabled="!submit" placeholder="请输入问题描述" v-model="detail.content" type="text" class="form-crl"
						maxlength="500" />
				</view>
			</view>
		</view>
		<view v-if="submit" class="btn-item">
			<view class="btn" @click="handleSave">提交</view>
		</view>
	</view>
</template>

<script>
	import {
		validate
	} from '@/util/validate.js'
	import {representInfo,saveMessage,findMessageDetail} from '@/api/represent.js'
	import { getStorage } from '../../util/auth'
	export default {
		data() {
			return {
				submit:true,
				info: {
					
				},
				detail: {
					rid:null,
					name: '',
					mobile: '',
					content: ''
				},
				rules: {
					name: {
						name: '反映人姓名',
						required: true,
					},
					mobile: {
						name: '反映人姓名电话',
						required: true,
					},
					content: {
						name: '问题描述',
						required: true,
					},
				}
			}
		},
		methods: {
			navigate(url) {
				uni.navigateTo({
					url
				})
			},
			getInfo(id){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				representInfo(id).then(res=>{
					this.info=res;
					this.detail.rid=id;
				})
			},
			getDetail(id){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				findMessageDetail({id}).then(res=>{
					this.info=res.represent;
					this.detail=res;
				})
			},
			handleSave(){
				if(validate(this.detail,this.rules)){
					uni.showLoading({
						title:'提交中',
						mask:true
					})
					saveMessage(this.detail).then(res=>{
						this.showToast('提交成功',()=>{
							uni.navigateBack();
						})
					})
				}
			}
		},
		onLoad(e) {
			if(e.id){
				this.getInfo(e.id)
				this.detail.mobile=getStorage('user').phone_number
				return;
			}
			if(e.detail_id){
				this.getDetail(e.detail_id);
				this.submit=false;
				return;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background-color: #F7F7F9;
		padding: 30rpx;
		min-height: 100vh;

		.info-block {
			background-color: #fff;
			border-radius: 30rpx;
			padding: 20rpx;
			margin-bottom: 20rpx;

			.title {
				font-size: 34rpx;
				color: #BB151C;
				margin-bottom: 30rpx;
				margin-top: 20rpx;
			}

			.info-item {
				width: 100%;
				display: flex;

				.info-img {
					width: 210rpx;
					height: 290rpx;
					background-color: #BB151C;
					margin-right: 16rpx;
					border-radius: 16rpx;
				}

				.name-item {
					width: calc(100% - 230rpx);

					.name {
						font-size: 32rpx;
						font-weight: bold;
						margin-bottom: 16rpx;
					}

					.type {
						color: #767676;
						font-size: 28rpx;
						margin-bottom: 16rpx;
					}

					.btn {
						background-color: #BB151C;
						font-size: 22rpx;
						color: #fff;
						width: 140rpx;
						height: 50rpx;
						border-radius: 30rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}
			}

			.form-block:last-child {
				border-bottom: none;
			}

			.form-block {
				display: flex;
				flex-direction: column;
				border-bottom: 1px solid #F7F6F9;

				.title-item {
					display: flex;
					align-items: center;
					line-height: 80rpx;

					.must {
						color: #BA1519;
					}
				}

				.form-item {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.form-crl {
						flex-grow: 1;
						height: 90rpx;
						font-size: 30rpx;
						line-height: 90rpx;
						font-weight: bold;
					}
				}
			}
		}

		.btn-item {
			width: 100%;
			display: flex;
			justify-content: center;
			margin: 50rpx auto;

			.btn {
				background-color: #BA1519;
				color: #fff;
				width: 400rpx;
				height: 100rpx;
				border-radius: 60rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
	}
</style>